package study.feign;

import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import study.dao.entity.MovieUser;

@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient>{

	@Override
	public UserFeignClient create(Throwable cause) {

		System.out.println("回退原因：" + cause.getMessage());

		//官网是这样
//		UserFeignClientImpl impl = new UserFeignClientImpl() {
//
//			@Override
//			public MovieUser selectById(int id) {
//				MovieUser user = new MovieUser();
//				user.setId(-1);
//				return user;
//			}
//		};


		//直接用匿名内部类
		UserFeignClient impl = new UserFeignClient() {

			@Override
			public MovieUser selectById(int id) {
				MovieUser user = new MovieUser();
				user.setId(-1);
				return user;
			}
		};

		return impl;
	}

}
